package com.youngwang.controller;

import com.youngwang.entity.UserEntity;
import com.youngwang.service.UserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author youngwang
 *         Date: 2016/9/20
 */

@Controller
@CrossOrigin
@RequestMapping(path = "user")
public class UserController {

    @Autowired
    private UserService userService;


    @GetMapping(path = "login")
    @ApiOperation("登录")
    public ModelAndView login(@RequestParam("username") String name, @RequestParam("password") String phone) {
        UserEntity userEntity = userService.login(name, phone);
        ModelAndView mv = new ModelAndView();
        if (ObjectUtils.isEmpty(userEntity)) {
            mv.setStatus(HttpStatus.BAD_REQUEST);
            mv.setViewName("error");
            return mv;
        } else {
            mv.setViewName("index");
            return mv;
        }
    }
}
